package com.library.management.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.library.management.common.PageResult;
import com.library.management.entity.BookCategory;
import com.library.management.mapper.BookCategoryMapper;
import com.library.management.service.BookCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 图书分类服务实现类
 */
@Service
public class BookCategoryServiceImpl implements BookCategoryService {
    @Autowired
    private BookCategoryMapper bookCategoryMapper;

    @Override
    public int add(BookCategory bookCategory) {
        return bookCategoryMapper.insert(bookCategory);
    }

    @Override
    public int delete(Long id) {
        return bookCategoryMapper.deleteById(id);
    }

    @Override
    public int update(BookCategory bookCategory) {
        return bookCategoryMapper.update(bookCategory);
    }

    @Override
    public BookCategory getById(Long id) {
        return bookCategoryMapper.selectById(id);
    }

    @Override
    public PageResult<BookCategory> list(BookCategory bookCategory, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<BookCategory> list = bookCategoryMapper.selectList(bookCategory);
        PageInfo<BookCategory> pageInfo = new PageInfo<>(list);
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public List<BookCategory> listAll() {
        return bookCategoryMapper.selectAll();
    }
}